Skip to content

Replace jsrsasign dependency with alternatives#2414

Open
lzandman wants to merge 17 commits into
gchq:masterfrom
lzandman:replace-jsrsasign-package
Open

Replace jsrsasign dependency with alternatives#2414
lzandman wants to merge 17 commits into
gchq:masterfrom
lzandman:replace-jsrsasign-package

Conversation

@lzandman
Copy link
Copy Markdown
Contributor

Summary

Removes the unmaintained jsrsasign library (which has reached end-of-support) and replaces it with actively-maintained, audited alternatives across all 14 affected operations and library files.

This PR fixes issue #2325.

Motivation

jsrsasign announced end-of-support. Continuing to ship an unmaintained cryptography library is a security risk. This PR completes a full migration to drop it entirely.

Replacement Libraries

Library Used for
@noble/curves ^2.2.0 ECDSA sign/verify/key-gen, signature format conversion, SM2 curve
@peculiar/x509 ^1.14.3 X.509 cert, PKCS#10 CSR, X.509 CRL parsing; SPKI/PKCS#8 key handling
asn1js ^3 Generic ASN.1 parse and tree dump
node-forge (already a dep) DSA path in PubKeyFromPrivKey only

@peculiar/x509 is pinned to ^1.14.3 (not v2) because v2 requires a reflect-metadata polyfill at every webpack entry point.

Changes

New library files

  • src/core/lib/Asn1.mjs — OID encode/decode, DER-to-PEM, ASN.1 hex tree dump
  • src/core/lib/Ecdsa.mjs — shared ECDSA helpers (key load, sign/verify, signature format conversions, key generation)
  • src/core/lib/KeyConvert.mjs — RSA/EC/DSA PEM⇄JWK⇄SPKI/PKCS#8 conversion helpers
  • src/core/lib/X509.mjs — shared X.509 helpers (SPKI describer, SAN/GeneralName formatter, sig-OID table, etc.)

Migrated operations

  • ASN.1 / encoding: HexToObjectIdentifier, ObjectIdentifierToHex, HexToPEM, ParseASN1HexString
  • ECDSA: ECDSASign, ECDSAVerify, ECDSASignatureConversion, GenerateECDSAKeyPair
  • Key conversion: PEMToJWK, JWKToPem, PubKeyFromPrivKey
  • X.509 / CSR / CRL: ParseX509Certificate, PubKeyFromCert, ParseCSR, ParseX509CRL
  • SM2: src/core/lib/SM2.mjs — full rewrite on @noble/curves abstract Weierstrass

New test coverage

  • tests/operations/tests/ASN1.mjs — OID round-trips, PEM line-wrapping, ASN.1 dumps
  • tests/operations/tests/ParseX509Certificate.mjs — golden output for RSA and P-256 certs, empty-input guard

Documentation

  • CRYPTO_IMPLEMENTATION.md (new) — captures library choices, coding conventions, and maintenance guidance established during this migration. Intended as a long-term reference for future contributors working on cryptographic operations.
  • CHANGELOG.md — updated to note the removal and accepted cosmetic output-format drift

Cosmetic output drift (accepted)

Text output of ParseX509Certificate, ParseCSR, ParseX509CRL, and ParseASN1HexString may differ slightly from the jsrsasign-based output (e.g. extension ordering, ECDSA r/s byte representation). All changes are corrections or reformatting — not regressions — and are documented in CHANGELOG.md.

Note on PLAN_JSRSASIGN-REMOVAL.md

PLAN_JSRSASIGN-REMOVAL.md is included in this branch as a detailed record of the migration plan and decisions made across each phase. It should be deleted before merging if you do not want it in the main repository; it was retained here as a reference for reviewers who want to understand the rationale and scope of the work.

AI Disclosure

Claude Code (Anthropic) was used to assist with the implementation of this migration — specifically to generate the replacement library code, translate jsrsasign API calls to their equivalents, write new test fixtures, and verify cryptographic correctness of the output. All generated code was reviewed and tested before inclusion.

@GCHQDeveloper581
Copy link
Copy Markdown
Contributor

Due diligence check on libraries added:

  • no reported supply chain issues with these versions
  • all have been published for a while now
  • all have multi-million weekly downloads

@lzandman
Copy link
Copy Markdown
Contributor Author

Due diligence check on libraries added:
* no reported supply chain issues with these versions
* all have been published for a while now
* all have multi-million weekly downloads

Yeah, these were my criteria when looking for replacements.

@GCHQDeveloper581
Copy link
Copy Markdown
Contributor

Due diligence check on libraries added:

  • no reported supply chain issues with these versions
  • all have been published for a while now
  • all have multi-million weekly downloads

Yeah, these were my criteria when looking for replacements.

The comment was mostly for my colleagues to indicate that a maintainer had done those checks (and specifically before kicking off the CI run)

@lzandman
Copy link
Copy Markdown
Contributor Author

The comment was mostly for my colleagues to indicate that a maintainer had done those checks

Ah, OK. I do think it's important that this PR be reviewed thoroughly. While I did my best, I did have to rely on AI to assist me for various parts. The code seems valid and it passes the tests. But still...

@GCHQDeveloper581
Copy link
Copy Markdown
Contributor

Our concern with this one is that it moves a lot of code out of libraries and into the CyberChef code base leaving us with ongoing maintenance overhead.

This is doubly so as it is crypto-related code, and as all the adages say - you should never try to roll your own crypto (and likely particularly so when that code has been AI generated/assisted).

We'll continue to look at it, but it probably isn't worth spending a lot of time polishing it (merging from master etc) until we come to a conclusion about whether it's the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants